<?php

class App_Model_Article extends Ext_Db_Table
{
    public function getMyHomeCount($userId)
    {
        $db = $this->getAdapter();
        $select = $db->select();
        $select
            ->from($this->_dbprefix."article_search_threads AS a", array(
               Zend_Paginator_Adapter_DbSelect::ROW_COUNT_COLUMN => 'COUNT(*)'
            ))
            ;
        $select
            ->join($this->_dbprefix."buddy AS b", 'a.userId=b.buddyUserId', '')
            ->where('b.userId = :userId')
            ;
        $params = array('userId' => $userId);
        $select->bind($params);
        
        return $select;
    }
    
    public function getMyHomeList($userId)
    {
        $db = $this->getAdapter();
        $select = $db->select();
        $select
            ->from($this->_dbprefix."article_search_threads AS a", "articleId")
            ->order('a.id DESC')
            //->limit(6)
            ;
        $select
            ->join($this->_dbprefix."buddy AS b", 'a.userId=b.buddyUserId', '')
            ->where('b.userId = :userId')
            ;
        $params = array('userId' => $userId);
        $select->bind($params);
        
        return $select;
    }
    
    public function getMyBlogCount($userId)
    {
        $db = $this->getAdapter();
        $select = $db->select();
        $select
            ->from($this->_dbprefix."article_search_threads", array(
               Zend_Paginator_Adapter_DbSelect::ROW_COUNT_COLUMN => 'COUNT(*)'
            ))
            ->where('userId = :userId')
            ;
        $params = array('userId' => $userId);
        $select->bind($params);
        
        return $select;
    }
    
    public function getMyBlogList($userId)
    {
        $db = $this->getAdapter();
        $select = $db->select();
        $select
            ->from($this->_dbprefix."article_search_threads", "articleId")
            ->order('id DESC')
            ->where('userId = :userId')
            ;
        $params = array('userId' => $userId);
        $select->bind($params);
        
        return $select;
    }
    
    public function getSearchCountByTag($tagId)
    {
        $db = $this->getAdapter();
        $select = $db->select();
        $select
            ->from($this->_dbprefix."article_search_tags", array(
               Zend_Paginator_Adapter_DbSelect::ROW_COUNT_COLUMN => 'COUNT(*)'
            ))
            ->where('tagId = :tagId')
            ;
        $params = array('tagId' => $tagId);
        $select->bind($params);
        
        return $select;
    }
    
    public function getSearchListByTag($tagId)
    {
        $db = $this->getAdapter();
        $select = $db->select();
        $select
            ->from($this->_dbprefix."article_search_tags", "articleId")
            ->order('id DESC')
            ->where('tagId = :tagId')
            ;
        $params = array('tagId' => $tagId);
        $select->bind($params);
        
        return $select;
    }
}